#!/usr/bin/env python

import sys

def get_combinations(parameters):
    
    if not parameters: yield []
    else:
        for value in parameters[0]:
            for next in get_combinations(parameters[1:]):
                yield [value] + next 

assert list(get_combinations([])) == [[]]
assert list(get_combinations([[1], [2]])) == [[1, 2]]
assert list(get_combinations([[1, 2], [3]])) == [[1, 3], [2, 3]]
assert list(get_combinations([ [1,2], [3, 4], [5,6] ])) == [[1,3,5], [1,3,6], [1,4,5], [1,4,6], [2,3,5], [2,3,6], [2,4,5], [2,4,6]]

if __name__ == '__main__':
    
    if len(sys.argv) != 2:
        print 'Error! Usage: <a file with the values of parameters in each line separated by whitespace>'
        sys.exit(1)
    
    file_name = sys.argv[1]
    
    h = open(file_name,'r')
    parameters = [l.strip().split() for l in h.readlines() if l.strip() and not l.strip().startswith('#')]
    h.close()
    
    for combination in get_combinations(parameters):
        print ' '.join(combination)